﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class EntityKeywordsController : ControllerBase
    {

        private readonly IEntityKeywordAppService _app;
        public EntityKeywordsController(IEntityKeywordAppService app)
        {
            this._app = app;
        }
        [HttpGet]
        [Route("entityKeywords/{id:Guid}")]
        public ActionResult<EntityKeywordDto> Get([FromRoute] Guid id)
        {
            EntityKeywordDto entityKeyword = _app.Get(id);
            return Ok(entityKeyword);
        }

        [HttpGet]
        [Route("entities/{entityId:Guid}/entityKeywords")]
        public ActionResult<IEnumerable<EntityKeywordDto>> GetList([FromRoute] Guid entityId)
        {
            IEnumerable<EntityKeywordDto> list = _app.GetList(entityId);
            return Ok(list);
        }

        [HttpPut]
        [Route("entityKeywords/{id:Guid}")]
        public ActionResult<EntityKeywordDto> Put([FromRoute] Guid id, [FromBody] EntityKeywordUpdateDto dto)
        {
            EntityKeywordDto entityKeyword = _app.Update(id, dto);
            return Ok(entityKeyword);
        }

        [HttpPost]
        [Route("entities/{entityId:Guid}/entityKeywords")]
        public ActionResult<EntityKeywordDto> Post([FromRoute] Guid entityId, [FromBody] EntityKeywordCreateDto dto)
        {
            EntityKeywordDto entityKeyword = _app.Add(entityId, dto);
            return CreatedAtAction(nameof(Get), new { id = entityKeyword.Id }, entityKeyword);
        }

        [HttpDelete]
        [Route("entityKeywords/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }        
    }
}
